using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;

namespace Exerciese.Model.model
{
    public partial class Crowd_Funding : DbContext
    {
        public Crowd_Funding()
            : base("name=Crowd_Funding")
        {
        }

        public virtual DbSet<T_Accomplish> T_Accomplish { get; set; }
        public virtual DbSet<T_Administrator_User> T_Administrator_User { get; set; }
        public virtual DbSet<T_AttenTion> T_AttenTion { get; set; }
        public virtual DbSet<T_Information> T_Information { get; set; }
        public virtual DbSet<T_Project> T_Project { get; set; }
        public virtual DbSet<T_Project_Class> T_Project_Class { get; set; }
        public virtual DbSet<T_ProJect_ImaGe> T_ProJect_ImaGe { get; set; }
        public virtual DbSet<T_Project_Pass> T_Project_Pass { get; set; }
        public virtual DbSet<T_Project_Review> T_Project_Review { get; set; }
        public virtual DbSet<T_ProJect_SucceeD> T_ProJect_SucceeD { get; set; }
        public virtual DbSet<T_Project_Support> T_Project_Support { get; set; }
        public virtual DbSet<T_Project_Update> T_Project_Update { get; set; }
        public virtual DbSet<T_User> T_User { get; set; }
        public virtual DbSet<T_User_MoDe> T_User_MoDe { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<T_Accomplish>()
                .HasMany(e => e.T_Project)
                .WithRequired(e => e.T_Accomplish)
                .HasForeignKey(e => e.Terrace)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<T_Administrator_User>()
                .Property(e => e.Intro)
                .IsFixedLength();

            modelBuilder.Entity<T_Administrator_User>()
                .HasOptional(e => e.T_Administrator_User1)
                .WithRequired(e => e.T_Administrator_User2);

            modelBuilder.Entity<T_Project>()
                .HasMany(e => e.T_ProJect_ImaGe)
                .WithRequired(e => e.T_Project)
                .HasForeignKey(e => e.ProJect_ID)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<T_Project>()
                .HasMany(e => e.T_ProJect_SucceeD)
                .WithRequired(e => e.T_Project)
                .HasForeignKey(e => e.ProJect_ID)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<T_Project_Class>()
                .HasMany(e => e.T_Project)
                .WithRequired(e => e.T_Project_Class)
                .HasForeignKey(e => e.project_Class)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<T_Project_Pass>()
                .HasMany(e => e.T_Project)
                .WithRequired(e => e.T_Project_Pass)
                .HasForeignKey(e => e.Project_Status)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<T_User>()
                .HasMany(e => e.T_Information)
                .WithRequired(e => e.T_User)
                .HasForeignKey(e => e.UserID)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<T_User>()
                .HasMany(e => e.T_Project)
                .WithRequired(e => e.T_User)
                .HasForeignKey(e => e.UserID)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<T_User>()
                .HasMany(e => e.T_Project_Review)
                .WithRequired(e => e.T_User)
                .HasForeignKey(e => e.UserID)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<T_User>()
                .HasMany(e => e.T_Project_Support)
                .WithRequired(e => e.T_User)
                .HasForeignKey(e => e.UserID)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<T_User_MoDe>()
                .HasMany(e => e.T_User)
                .WithRequired(e => e.T_User_MoDe)
                .HasForeignKey(e => e.User_modeID)
                .WillCascadeOnDelete(false);
        }
    }
}
